Skip to content

fix: suppress OkHttp default User-Agent header on outbound requests#30

Open
chrismParticle wants to merge 1 commit into
mParticle:mainfrom
chrismParticle:fix/okhttp-user-agent
Open

fix: suppress OkHttp default User-Agent header on outbound requests#30
chrismParticle wants to merge 1 commit into
mParticle:mainfrom
chrismParticle:fix/okhttp-user-agent

Conversation

@chrismParticle
Copy link
Copy Markdown
Contributor

Summary

  • Adds a UserAgentInterceptor (network interceptor) to ApiClient that strips OkHttp's default User-Agent header (okhttp/<version>) after BridgeInterceptor injects it
  • Wired in both createDefaultAdapter() and configureFromOkclient() so all construction paths are covered
  • Caller-supplied User-Agent values (set via a custom OkHttp interceptor) are detected and passed through unchanged
  • This resolves cases where mParticle was enriching device_info.http_header_user_agent with a meaningless library-identifier string

Version

Changelog entry added for 2.8.0.

Test plan

  • New test class ApiClientUserAgentTest covers three cases using MockWebServer: default path (no UA), caller override preserved, and configureFromOkclient path
  • ./gradlew test — 9 tests, all passing
  • Manually verified against mParticle Live Stream: batch without UA shows no device_info.http_header_user_agent; batch with User-Agent: my_app shows my_app correctly

Notes

  • Uses addNetworkInterceptor (not addInterceptor) — required because OkHttp's BridgeInterceptor runs between application and network interceptors and re-injects the default UA if the header is absent at the application layer
  • RateLimitInterceptor is unchanged
  • No public API surface changes

🤖 Generated with Claude Code

@cursor
Copy link
Copy Markdown

cursor Bot commented May 19, 2026

PR Summary

Medium Risk
Changes request header behavior by stripping OkHttp’s implicit User-Agent, which could affect integrations that relied on seeing that value; covered by focused MockWebServer tests and preserves caller-supplied User-Agents.

Overview
Prevents leaking OkHttp’s default User-Agent (okhttp/<version>) by adding a network UserAgentInterceptor to ApiClient that removes only that auto-injected header on the wire (while leaving any caller-set User-Agent intact), and applies it both in the default client setup and the configureFromOkclient() path.

Adds MockWebServer-based tests to verify no User-Agent is sent by default, custom User-Agent overrides are preserved, and the behavior holds when configuring from an external OkHttpClient. Updates docs/CHANGELOG for the new behavior and adds the mockwebserver test dependency.

Reviewed by Cursor Bugbot for commit 29503b1. Bugbot is set up for automated code reviews on this repo. Configure here.

@chrismParticle chrismParticle force-pushed the fix/okhttp-user-agent branch 2 times, most recently from e9b7eab to 0e389b2 Compare May 19, 2026 00:17
Adds a UserAgentInterceptor (network interceptor) to ApiClient that
removes the okhttp/<version> User-Agent header injected by OkHttp's
BridgeInterceptor. This prevents mParticle from enriching
device_info.http_header_user_agent with a meaningless SDK string.
Caller-supplied User-Agent values are preserved. Wired in both
createDefaultAdapter() and configureFromOkclient().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chrismParticle chrismParticle force-pushed the fix/okhttp-user-agent branch from 0e389b2 to 29503b1 Compare May 19, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant